<?php

namespace IDock\Insurance\JTIC\Request;

use IDock\Insurance\JTIC\Response\UnderwritingResponse;
use IDock\Insurance\JTIC\JTICEnums;
use IDock\Visitor\Premium\PremiumInquiryVisitor;
use IDock\Visitor\SpecialClausesVisitor;

class UnderwritingRequest extends AllJTICRequest
{
    protected $code = 'V103';

    protected $response = UnderwritingResponse::class;

    protected $urlTip = '提交核保';

    /*** @var  PremiumInquiryVisitor $visitor */
    protected $visitor;

    public function generate(): array
    {

        $appSpecTCIList = [];
        $appSpecVCIList = [];

        /*** @var $specialClauses SpecialClausesVisitor */
        foreach ($this->visitor->getUnderwritingVisitor()->specialClausesList as $specialClauses) {
            if ($specialClauses->riskType == 'TCI') {
               $appSpecTCIList[] = [
                   'SpecNo' => $specialClauses->clauseCode,
                   'SpecName' => $specialClauses->clauseName,
                   'SpecTemplate' => $specialClauses->clauseContent
               ];
            }
            if ($specialClauses->riskType == 'VCI') {
                $appSpecVCIList[] = [
                    'SpecNo' => $specialClauses->clauseCode,
                    'SpecName' => $specialClauses->clauseName,
                    'SpecTemplate' => $specialClauses->clauseContent
                ];
            }
        }

        return [
            'BasePart' => [
                'QtnId' => $this->visitor->getUnderwritingVisitor()->inquiryNo,
                'ManualUndr' => '1',
                'GenerateSpec' => '1',
                'Remark' => $this->visitor->getExtInfoVisitor()->underwriteMsg,
            ],
            'Applicant' => [
                'AppName' => $this->visitor->getApplicantVisitor()->name,
                'AppType' => JTICEnums::$relationTypeCode[$this->visitor->getApplicantVisitor()->typeCode],
                'AppCertfCls' => JTICEnums::$certificateTypeCode[$this->visitor->getApplicantVisitor()->certificateTypeCode],
                'AppCertfCode' => $this->visitor->getApplicantVisitor()->certificateNo,
                'AppMobile' => $this->visitor->getApplicantVisitor()->mobile,
                'AppAddr' => $this->visitor->getApplicantVisitor()->address,
                'AppEmail' => $this->visitor->getApplicantVisitor()->email,
            ],
            'Insured' => [
                'InsuredName' => $this->visitor->getInsuredVisitor()->name,
                'InsuredType' => JTICEnums::$relationTypeCode[$this->visitor->getInsuredVisitor()->typeCode],
                'InsuredCertfCls' => JTICEnums::$certificateTypeCode[$this->visitor->getInsuredVisitor()->certificateTypeCode],
                'InsuredCertfCode' => $this->visitor->getInsuredVisitor()->certificateNo,
                'InsuredMobile' => $this->visitor->getInsuredVisitor()->mobile,
                'InsuredAddr' => $this->visitor->getInsuredVisitor()->address,
                'InsuredEmail' => $this->visitor->getInsuredVisitor()->email,
            ],
            'AppSpecTCIList' => $appSpecTCIList,
            'AppSpecVCIList' => $appSpecVCIList,
        ];
    }
}
